package com.example.Controller;

import com.example.Service.impl.ExchangeServiceImpl;
import com.example.pojo.Exchange;
import com.example.pojo.User;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exchange")
public class ExchangeController {

    @Autowired
    private ExchangeServiceImpl exchangeService;

    //所有聊天人展示
    @GetMapping("/selectAllLinkman")
    public Result selectAllLinkman() {
        List<User> userList = exchangeService.selectAllLinkman();
        return new Result("200","查询成功",userList);
    }

    //联系人的历史聊天记录
    @GetMapping("/chattingRecordsBySenderAndRecipient")
    public Result chattingRecordsBySenderAndRecipient(@RequestParam(required = false, defaultValue = "null") String sender,
                                                      @RequestParam(required = false, defaultValue = "null") String recipient) {
        List<Exchange> exchangeList = exchangeService.chattingRecordsBySenderAndRecipient(sender, recipient);
        return new Result("200","查询成功",exchangeList);
    }

    //查看登录人（用户）与每个联系人之间的未读信息数量
    @GetMapping("/senderUnreadQuantity")
    public Result senderUnreadQuantity(@RequestParam(required = false, defaultValue = "null") String sender) {
        List<Exchange> exchangeList = exchangeService.senderUnreadQuantity(sender);
        return new Result("200","查询成功",exchangeList);
    }


    //发送信息进行交流   发送者 ---->  接收者
    @PostMapping("/senderExchange")
    public Result senderExchange(@RequestBody Exchange exchange) {
        exchangeService.senderExchange(exchange);
        return new Result("200","添加成功");
    }


    //修改未读   点击与接收者的聊天内容 ------> 未读的信息变成 已读的信息
    @PutMapping("/updateUnread")
    public Result updateUnread(@RequestParam(required = false, defaultValue = "null") String sender,
                               @RequestParam(required = false, defaultValue = "null") String recipient) {

        exchangeService.updateUnread(sender,recipient);
        return new Result("200","修改成功");
    }





}
